package com.sh.data.engine.repository.dao.datadev.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.sh.data.engine.repository.dao.base.EngineBaseModel;
import lombok.*;

import java.util.Date;
import java.util.List;

@Data
@TableName(value = "tb_flink_node_config", autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FlinkNodeConfigEntity extends EngineBaseModel<FlinkNodeConfigEntity> {

    private Long projectId;

    private Long nodeId;

    private Integer isPublished;

    private String publisherId;

    private Date publishTime;

    private Integer isActive;

    private Date nextExecTime;

    private Date nextStopTime;

    /**
     * @see com.sh.data.engine.common.enumDefinition.FlinkNodeTypeEnum
     */
    private Integer nodeType;

    /**
     * 调度配置
     */
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private FlinkScheduleConfig scheduleConfig;

    /**
     * 环境参数配置
     */
    private String envConfig;

    // flinksql
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private SqlTaskConfig sqlTaskConfig;

    // flink
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private JarTaskConfig jarTaskConfig;

    // 资源
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private ResourceConfig resourceConfig;

    // 函数
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private FunctionConfig functionConfig;

    private String remark;

    @Data
    public static class FlinkScheduleConfig {

        /**
         * 生效区间 0-每天 1-周一到周五
         */
        private Integer effectDayType;

        /**
         * 日期范围
         */
        public List<FlinkScheduleDayRange> rangeList;

        /**
         * 执行开始时间的小时
         */
        private Integer startTimeHour;

        /**
         * 执行开始时间的分钟
         */
        private Integer startTimeMin;

        /**
         * 执行结束时间的小时
         */
        private Integer endTimeHour;

        /**
         * 执行结束时间的分钟
         */
        private Integer endTimeMin;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FlinkScheduleDayRange {

        /**
         * 生效日期（开始） yyyy-MM-dd
         */
        private String effectiveDateStart;

        /**
         * 生效日期（结束） yyyy-MM-dd
         */
        private String effectiveDateEnd;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class SqlTaskConfig {
        /**
         * 脚本内容
         */
        private String scriptContent;

        /**
         * 源表配置
         */
        private String sourceConfig;

        /**
         * 结果表配置
         */
        private String sinkConfig;

        /**
         * 维度表配置
         */
        private String dimConfig;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class JarTaskConfig {

        private Long resourceNodeId;

        private String mainClass;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ResourceConfig {
        /**
         * 文件存储路径
         */
        private String path;

        /**
         * 文件名称
         */
        private String fileName;

        //    private String publisherId;
        //
        //    private Date publishTime;

        // 0-不生效  1-生效
        private Integer isActive;

        private String remark;

        private String resourceName;

        private String fileDownloadUrl;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class FunctionConfig {

        /**
         * @see com.xuelangyun.hufu.common.enumDefinition.FlinkFunctionTypeEnum
         */
        private Integer functionType;

        /**
         * 类名
         */
        private String className;

        /**
         * 资源id
         */
        private Long resourceNodeId;

        /**
         * 用途
         */
        private String purpose;

        /**
         * 命令格式
         */
        private String format;

        /**
         * 参数说明
         */
        private String paramDesc;
    }


}
